package src

import "pp/comm"

type (
	UserItf interface {
		GetID() uint32
		GetConn() string
	}
	User struct {
		id uint32
	}
)

func (c *User) GetID() uint32 {
	return c.id
}
func (c *User) GetConn() string {
	return ""
}

func DoUser() {
	var (
		id uint32 = 22
	)
	if v := getUser(id); v == nil {
		comm.Println("get user nil", id)
	} else {
		comm.Printf("get user:%+v, %+v\n", v != nil, v.GetID())
	}
}

// 获取接口与nil比较:https://blog.csdn.net/chenchongg/article/details/86706914
func getUser(id uint32) UserItf {
	users := map[uint32]*User{}
	users[2] = &User{id: 101}
	delete(users, 21)
	if v := users[id]; v != nil {
		return v
	}
	return nil
	//return users[id]
}
